package com.atguigu.exam;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;

/**
 * 利用程序读取 test.txt 文件的内容, 并在控制台打印
 * @author xbd
 * @create 2021-05-30 16:15
 */
public class PrintTxtTest {
    public static void main(String[] args) {
        BufferedInputStream bis = null;
        try {
            bis = new BufferedInputStream(new FileInputStream(new File("test.txt")));
            byte[] bytes = new byte[5];
            int len;
            while((len = bis.read(bytes)) != -1){
                System.out.print(new String(bytes, 0, len));
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if(bis != null){
                try {
                    bis.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
